package com.zmn.oms.api.controller.third.eliao;

import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.common.utils.RequestUtil;
import com.zmn.oms.third.eliao.EasyLiaoConsts;
import com.zmn.oms.third.eliao.service.EasyLiaoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

/**
 * 类描述：12729易聊对外接口
 *  用于12729易聊平台向ZMN平台进行订单推送
 *
 * @author XieWenBing
 * @date 2020/11/20 11:00
 */
@RestController
@RequestMapping("/easyLiao")
@Slf4j
public class EasyLiaoController {

    @Autowired
    protected EasyLiaoService easyLiaoService;

    @PostMapping("/api/pushOrder")
    @ResponseBody
    public ResultDTO pushOrder(HttpServletRequest request) {

        String paramsStr = RequestUtil.getPostParameter(request);
        
        try {
            easyLiaoService.createOrder(paramsStr);
        } catch (OmsBaseException exception) {
            
            return ResultDTO.fail(Optional.ofNullable(exception.getMessage()).orElse("创建订单消息处理失败"));
        }

        return ResultDTO.success(200,"success");
    }
}
